package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.PersonnelDetailsDao;
import com.itheima.entity.PageResult;
import com.itheima.pojo.Personnel;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 企业个人信息查询服务
 */
@Service(interfaceClass = PersonnelDetailsService.class)
@Transactional
public class PersonnelDetailsServiceImpl implements PersonnelDetailsService {
    @Autowired
    public PersonnelDetailsDao personnelDetailsDao;

    @Override
    public PageResult findPage(Integer currentPage, Integer pageSize, String queryString) {
        //完成分页查询，基于mybatis的分页助手插件完成
        PageHelper.startPage(currentPage, pageSize);
        List<Personnel> pages = personnelDetailsDao.selectByCondition(queryString);
        PageInfo<Personnel> info = new PageInfo<>(pages);
        return new PageResult(info.getTotal(), pages);
    }

    @Override
    public void add(Personnel personnel) {
        personnelDetailsDao.add(personnel);
    }

    @Override
    public Personnel findById(Integer id) {

        return personnelDetailsDao.findById(id);
    }

    @Override
    public void delete(Integer id) {
        personnelDetailsDao.delete(id);
    }

    @Override
    public void edit(Personnel personnel) {
        personnelDetailsDao.edit(personnel);
    }
}
